﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Reflection;
using YSUtils.Reflection;

namespace UnitTest
{
    /// <summary>
    ///This is a test class for PropertyUtilTest and is intended
    ///to contain all PropertyUtilTest Unit Tests
    ///</summary>
	[TestClass]
	public class PropertyUtilTest
	{
		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get; set;
		}

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		/// <summary>
		/// Gets the public non-static property name.
		/// </summary>
		[TestMethod]
		public void GetNonStaticPropertyNameTest()
		{
			const string expected = "PropertyOne";

			var testProperties = new ClassWithProperties();
			var actual = testProperties.GetPropertyName(x => x.PropertyOne);
			Assert.AreEqual(expected, actual, "GetPropertyName failed.");

			actual = PropertyUtil.GetPropertyName<ClassWithProperties>(x => x.PropertyOne);
			Assert.AreEqual(expected, actual, "GetPropertyName failed.");
		}

		/// <summary>
		/// Gets the public static property name.
		/// </summary>
		[TestMethod]
		public void GetStaticPropertyNameTest()
		{
			const string expected = "PropertyTwo";

			var actual = PropertyUtil.GetPropertyName(() => ClassWithStaticProperties.PropertyTwo);
			Assert.AreEqual(expected, actual, "GetPropertyName failed.");
		}
	}
}
